Composition Root(组合根/装配根):软件工程(尤其是依赖注入 Dependency Injection)中的概念,指应用程序中集中创建对象并“组装”依赖关系的入口位置。通常在程序启动处(如 main、启动模块、应用初始化代码)把各组件连起来,避免在业务代码里到处 new 对象或直接依赖具体实现。
(在某些语境下也可泛指“组合结构的根节点”,但最常见用法来自 DI/IoC。)
The composition root is usually in the app’s startup code.
组合根通常位于应用程序的启动代码中。
By keeping all dependency wiring in the composition root, the team made the codebase easier to test, refactor, and maintain over time.
通过把所有依赖关系的装配都集中在组合根中,团队让代码库在长期内更易测试、重构和维护。
/ˌkɑːmpəˈzɪʃən ruːt/(美式常见)
/ˌkɒmpəˈzɪʃən ruːt/(英式常见)
composition 源自拉丁语 componere(com- “一起” + ponere “放置”),本义是“把东西放在一起、组合”。root 原义为“根”,在抽象意义上常指“源头/起点/根节点”。合起来 composition root 就是“进行组合(装配)的起点”。